home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 409_01 / svga.asm < prev    next >
Assembly Source File  |  1993-10-21  |  35KB  |  1,024 lines

  1. ;****************************************************************************
  2. ;*
  3. ;*                         SuperVGA Test Library
  4. ;*
  5. ;*                  Copyright (C) 1993 SciTech Software
  6. ;*                          All rights reserved.
  7. ;*
  8. ;* Filename:    $RCSfile: svga.asm $
  9. ;* Version:     $Revision: 1.2 $
  10. ;*
  11. ;* Language:    80386 Assembler
  12. ;* Environment: IBM PC (MS DOS)
  13. ;*
  14. ;* Description: Assembly language support routines for the SuperVGA test
  15. ;*              library.
  16. ;*
  17. ;* $Id: svga.asm 1.2 1993/10/22 08:58:40 kjb release $
  18. ;*
  19. ;****************************************************************************
  20.  
  21.         IDEAL
  22.         JUMPS
  23.         P386                    ; Use 386 instructions
  24.  
  25.         MODEL   large
  26.  
  27. CRTC            EQU 3D4h        ; Port of CRTC registers
  28. VGABufferSeg    EQU 0A000h      ; Segment of VGA display memory
  29.  
  30.         DATASEG
  31.  
  32.         COMM    _maxx:WORD
  33.         COMM    _maxy:WORD
  34.         COMM    _maxcolor:DWORD
  35.         COMM    _bytesperline:WORD
  36.         COMM    _pagesize:DWORD
  37.         COMM    _curBank:WORD
  38.         COMM    _bankSwitch:DWORD
  39.         COMM    _extendedflipping:WORD
  40.         COMM    _bankAdjust:WORD
  41.         COMM    _writeBank:DWORD; Relocated write bank routine
  42.         COMM    _readBank:DWORD ; Relocated read bank routine
  43.         COMM    _pageFlip:DWORD ; Relocated page flip routine
  44.  
  45. OriginOffset    dw  0           ; Starting offset within bank
  46. BankOffset      dw  0           ; Starting bank in video memory
  47.  
  48.         CODESEG
  49.  
  50. MACRO   procstart name          ; Set up model independant proc
  51. PROC    name
  52.         PUBLIC name
  53. ENDM
  54.  
  55. MACRO   procend name            ; End procedure macro
  56. ENDP    name
  57. ENDM
  58.  
  59. ;----------------------------------------------------------------------------
  60. ; void putPixel16(int x,int y,long color)
  61. ;----------------------------------------------------------------------------
  62. ; Routine sets the value of a pixel in native VGA graphics modes.
  63. ;
  64. ; Entry:        x       -   X coordinate of pixel to draw
  65. ;               y       -   Y coordinate of pixel to draw
  66. ;               color   -   Color of pixel to draw
  67. ;
  68. ;----------------------------------------------------------------------------
  69. procstart   __putPixel16
  70.  
  71.         ARG     x:WORD, y:WORD, color:DWORD
  72.  
  73.         push    bp                  ; Set up stack frame
  74.         mov     bp,sp
  75.  
  76. ; Compute the pixel's address in video buffer
  77.  
  78.         mov     ax,[y]
  79.         mov     bx,[x]
  80.         mul     [_bytesPerLine]     ; DX:AX := y * BytesPerLine
  81.  
  82.         mov     cl,bl               ; CL := low-order byte of x
  83.  
  84.         shr     bx,3                ; BX := x/8
  85.         add     bx,ax
  86.         adc     dx,0                ; DX:BX := y*BytesPerLine + x/8
  87.         add     bx,[OriginOffset]   ; DX:BX := byte offset in video buffer
  88.         adc     dx,[BankOffset]
  89.  
  90.         cmp     dl,[BYTE _curBank]
  91.         je      @@NoChange
  92.  
  93.         mov     ax,dx
  94.         call    setBank
  95.  
  96. @@NoChange:
  97.         mov     ax,VGABufferSeg
  98.         mov     es,ax               ; ES:BX := byte address of pixel
  99.  
  100.         mov     ah,1                ; AH := unshifted bit mask
  101.         and     cl,7                ; CL := x & 7
  102.         xor     cl,7                ; CL := # bits to shift left
  103.  
  104. ; set Graphics Controller Bit Mask register
  105.  
  106.         shl     ah,cl               ; AH := bit mask in proper postion
  107.         mov     dx,3CEh             ; GC address register port
  108.         mov     al,8                ; AL := Bit Mask Register number
  109.         out     dx,ax
  110.  
  111. ; set Graphics Controller Mode register
  112.  
  113.         mov     ax,0205h            ; AL := Mode register number
  114.                                     ; AH := Write mode 2 (bits 0,1)
  115.                                     ;   Read mode 0 (bit 3)
  116.         out     dx,ax
  117.  
  118. ; set data rotate/Function Select register
  119.  
  120.         mov     ax,3                ; AL := Data Rotate/Func select reg #
  121.         out     dx,ax
  122.  
  123. ; set the pixel value
  124.  
  125.         mov     al,[es:bx]          ; latch one byte from each bit plane
  126.         mov     al,[BYTE color]     ; AL := pixel value
  127.         mov     [es:bx],al          ; update all bit planes
  128.  
  129. ; restore default Graphics Controller registers
  130.  
  131.         mov     ax,0FF08h           ; default bit mask
  132.         out     dx,ax
  133.  
  134.         mov     ax,0005             ; default mode register
  135.         out     dx,ax
  136.  
  137.         mov     ax,0003             ; default function select
  138.         out     dx,ax
  139.  
  140.         pop     bp
  141.         ret
  142.  
  143. procend     __putPixel16
  144.  
  145. ;----------------------------------------------------------------------------
  146. ; void putPixel256(int x,int y,long color)
  147. ;----------------------------------------------------------------------------
  148. ; Routine sets the value of a pixel in native VGA graphics modes.
  149. ;
  150. ; Entry:        x       -   X coordinate of pixel to draw
  151. ;               y       -   Y coordinate of pixel to draw
  152. ;               color   -   Color of pixel to draw
  153. ;
  154. ;----------------------------------------------------------------------------
  155. procstart   __putPixel256
  156.  
  157.         ARG     x:WORD, y:WORD, color:DWORD
  158.  
  159.         push    bp                  ; Set up stack frame
  160.         mov     bp,sp
  161.  
  162.         mov     ax,[y]
  163.         mul     [_bytesperline]
  164.         add     ax,[x]
  165.         adc     dx,0                ; DX:AX := y * BytesPerLine + x
  166.         add     ax,[OriginOffset]
  167.         adc     dl,[BYTE BankOffset]; DL := bank number
  168.         mov     bx,ax               ; BX := Offset in buffer
  169.         cmp     dl,[BYTE _curBank]
  170.         je      @@NoChange
  171.  
  172.         mov     ax,dx
  173.         call    setBank
  174.  
  175. @@NoChange:
  176.         mov     ax,VGABufferSeg
  177.         mov     es,ax               ; ES:BX := byte address of pixel
  178.         mov     al,[BYTE color]
  179.         mov     [es:bx],al          ; Replace the pixel
  180.         pop     bp
  181.         ret
  182.  
  183. procend     __putPixel256
  184.  
  185. ;----------------------------------------------------------------------------
  186. ; void putPixel32k(int x,int y,long color)
  187. ;----------------------------------------------------------------------------
  188. ; Routine sets the value of a pixel in native VGA graphics modes.
  189. ;
  190. ; Entry:        x       -   X coordinate of pixel to draw
  191. ;               y       -   Y coordinate of pixel to draw
  192. ;               color   -   Color of pixel to draw
  193. ;
  194. ;----------------------------------------------------------------------------
  195. procstart   __putPixel32k
  196.  
  197.         ARG     x:WORD, y:WORD, color:DWORD
  198.  
  199.         push    bp                  ; Set up stack frame
  200.         mov     bp,sp
  201.  
  202.         mov     ax,[y]
  203.         mul     [_bytesperline]
  204.         mov     bx,[x]
  205.         shl     bx,1
  206.         add     ax,bx
  207.         adc     dx,0                ; DX:AX := y * BytesPerLine + x * 2
  208.         add     ax,[OriginOffset]
  209.         adc     dl,[BYTE BankOffset]; DL := bank number
  210.         mov     bx,ax               ; BX := Offset in buffer
  211.         cmp     dl,[BYTE _curBank]
  212.         je      @@NoChange
  213.  
  214.         mov     al,dl
  215.         call    setBank
  216.  
  217. @@NoChange:
  218.         mov     ax,VGABufferSeg
  219.         mov     es,ax               ; ES:BX := byte address of pixel
  220.         mov     ax,[WORD color]
  221.         mov     [es:bx],ax          ; Replace the pixel
  222.         pop     bp
  223.         ret
  224.  
  225. procend     __putPixel32k
  226.  
  227. ;----------------------------------------------------------------------------
  228. ; void putPixel64k(int x,int y,long color)
  229. ;----------------------------------------------------------------------------
  230. ; Routine sets the value of a pixel in native VGA graphics modes.
  231. ;
  232. ; Entry:        x       -   X coordinate of pixel to draw
  233. ;               y       -   Y coordinate of pixel to draw
  234. ;               color   -   Color of pixel to draw
  235. ;
  236. ;----------------------------------------------------------------------------
  237. procstart   __putPixel64k
  238.  
  239.         ARG     x:WORD, y:WORD, color:DWORD
  240.  
  241.         push    bp                  ; Set up stack frame
  242.         mov     bp,sp
  243.  
  244.         mov     ax,[y]
  245.         mul     [_bytesperline]
  246.         mov     bx,[x]
  247.         shl     bx,1
  248.         add     ax,bx
  249.         adc